const { Model, DataTypes } = require('sequelize')
const { Article } = require('./article')
const { sequelize } = require('./index')
const { User } = require('./user')

class Comment extends Model { }

Comment.init({
  content: {
    type: DataTypes.STRING,
  },
  uid: {
    type: DataTypes.INTEGER,
  },
  aid: {
    type: DataTypes.INTEGER,
  },
}, {
  sequelize,
  tableName: 't_comment',
})

User.hasMany(Comment, { as: 'Comments', foreignKey: 'uid' })
Comment.belongsTo(User, { as: "User", foreignKey: 'uid' })

Article.hasMany(Comment, { as: 'Comments', foreignKey: 'aid' })
Comment.belongsTo(Article, { as: 'Article', foreignKey: 'aid' })

module.exports = {
  Comment
}